package com.atguigu.tingshu.album.client;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.annotation.cache.Cache;
import com.atguigu.tingshu.model.album.AlbumAttributeValue;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Haoran Sun
 * @since 2024/08/21
 */

@RestController
@RequestMapping("client/album/albumInfo")
public class AlbumClientController {

    @Resource
    private AlbumInfoService albumInfoService;

    /**
     * 根据id查询专辑信息
     * <p>
     *     内部调用接口
     * </p>
     * @param id 专辑id
     * @return  专辑信息
     */
    @GetMapping("/getAlbumInfo/{id}")
    @Cache(value = "cache:album:getAlbumInfo")
    public AlbumInfo getAlbumInfo(@PathVariable("id") Long id){
        return albumInfoService.getById(id);
    }

    /**
     * 获取专辑统计信息
     * @param id 专辑id
     * @return 专辑统计信息
     */
    @GetMapping("/getAlbumStats/{id}")
    @Cache(value = "cache:album:getAlbumStats")
    public Map<String, Integer> getAlbumStats(@PathVariable("id") Long id){
        return albumInfoService.getAlbumStats(id);
    }

    /**
     * 查询专辑的标签
     * @param id 专辑id
     * @return 标签列表
     */
    @GetMapping("/getAlbumAttributes/{id}")
    @Cache(value = "cache:album:getAlbumAttributes")
    public List<AlbumAttributeValue> getAlbumAttributes(@PathVariable("id") Long id) {
        return albumInfoService.getAlbumAttributes(id);
    }

}
